package org.example.interrupt;

import java.util.concurrent.TimeUnit;

/**
 * @Title : InterruptThreadExit
 * @Description: :
 * @author: libo@juzishuke.com
 * @date: 2023/10/24 16:05
 * @Version:1.0
 */
public class InterruptThreadExit {

    public static void main(String[] args) throws InterruptedException {

        Thread t = new Thread() {
            @Override
            public void run() {
                System.out.println("I will start work");
                while (!isInterrupted()) {
                    //working.
                    System.out.println(" I am alive");
                }
                System.out.println("I will be exiting.");
            }
        };

        t.start();
        TimeUnit.MILLISECONDS.sleep(100);
        System.out.println(Thread.currentThread().getName() + " System will be shutdown.");
        t.interrupt();
    }
}
